package br.com.adimoveis.util.ui;

import javax.swing.AbstractSpinnerModel;

public class SpinnerModel extends  AbstractSpinnerModel {
	
    private int currentValue;
    
    private int maxVal = Integer.MAX_VALUE - 1;
    
    SpinnerModel linkedModel = null;

    public SpinnerModel() {
        currentValue = 0;
    }

    public void setLinkedModel(SpinnerModel linkedModel) {
        this.linkedModel = linkedModel;
    }

    public Object getNextValue() {
        if(currentValue <= maxVal){
        	currentValue ++;
        }
        fireStateChanged();
        return currentValue;
    }

    public Object getPreviousValue() {
        if(currentValue >= 1){
        	currentValue--;
        }
        fireStateChanged();
        return currentValue;
    }

	public Object getValue() {
		return currentValue;
	}

	public void setValue(Object value) {
		if(value instanceof Integer){
			currentValue = (Integer) value;
			fireStateChanged();
		}
	}
	
	public void setMaxValue(int maxValue){
		this.maxVal = maxValue;
	}
}

